package com.lz.football.module.playerCenter.item
{
	import com.common.utils.Reflection;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.type.GoodsType;
	import com.lz.football.module.club.item.BaseItem;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.utils.getTimer;

	/**
	 *球员装备ITem 
	 * @author Administrator
	 * 
	 */	
	public class PlayerEquipItem extends BaseItem
	{
		/**
		 *装备类型
		 * 1为属性卡 
		 * 2为装备卡
		 */		
		private var _type:int;
		/**
		 *双击时间 
		 */
		public var double_click_wait:int = 300;
		public var previousClick:int = 0;
		/**
		 *锁 
		 */
		private var _lockMc:MovieClip;
		public function PlayerEquipItem()
		{
			super();
			
		}

		override public function set data(value:Object):void
		{
			var goodsId:int = value.goodsId;
			var goodsVo:GoodsVo
//			if(value.type == GoodsType.ATTRIBUTE)
//				goodsVo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(GoodsType.ATTRIBUTE,goodsId);
//			else
			goodsVo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(value.type,goodsId);
			if(goodsVo == null)
			{
				reset();
				return ;
			}
			super.data = goodsVo;
			setImageSorce(goodsVo.bitmapData);
			tips = goodsVo.tipsInfo;
			if(value.lock == 1)
			{
				addLock();
			}else
			{
				if(_lockMc != null && _lockMc.parent)_lockMc.parent.removeChild(_lockMc);
			}
			
		}
		override public function reset():void
		{
			super.reset();
			if(_lockMc != null && _lockMc.parent)_lockMc.parent.removeChild(_lockMc);
		}
		/**
		 *加锁状态 
		 * 
		 */
		public function addLock():void
		{
			if(_lockMc == null)
				_lockMc = Reflection.createInstance("com.lz.commonUI.lock");
			_lockMc.x = _skin.width - _lockMc.width - 3;
			_lockMc.y = _skin.height - _lockMc.height - 3;
			_lockMc.mouseChildren = false;
			_lockMc.mouseEnabled = false;
//			this.addChild(_lockMc);
		}
		override public function onMouseClick(event:MouseEvent):void
		{
			if(getTimer() - previousClick < double_click_wait)//1表示主动使用 0表示被动使用)
			{
				if(callBack != null)callBack(this,true);
				//				this.dispatchEvent(new BagEvent(BagEvent.USE_ITEM,{pid:goodVo.pid,num:1},true));
				previousClick = 0;
				return;
			}
			previousClick = getTimer();
			if(callBack != null)callBack(this,false);
		}
		/**
		 * 
		 */
		public function get type():int
		{
			return _type;
		}

		/**
		 *装备类型
		 * 1为属性卡 
		 * 2为装备卡
		 * @private
		 */
		public function set type(value:int):void
		{
			_type = value;
			if(value == 0  || value == 1)
			{
				des.text = "属性卡";
			}else
			{
				des.text = "装备卡";
			}
			
		}

	}
}